<%@ page import="java.text.SimpleDateFormat"%>
<%@ page import="java.util.Iterator"%>
<%@ page import="uniLearn.control.*" %>
<%@ page import="uniLearn.data.*" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="java.util.Date" %>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%
	int acId = 2; //Assignment ID = 3
	String errMsg = ""; //For collector Error Message
	AssignmentCollector ac = null;
	ArrayList<AssignmentResult> listResult = null;
	//Get Assignment Detial
	try {
		AssignmentsControl assCon = new AssignmentsControl();
		ac = assCon.getAssignment(acId);
		
		ResultControl rCon = new ResultControl();
		listResult = rCon.getResultListByAssignment(acId);
		
		assCon.closeDBConnection();
		rCon.closeDBConnection();
		
	} catch (Exception e) {
		errMsg += e.toString() + "<br />\r\n";
	}
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Assignment Collector - Uni-Learn</title>
</head>
<body>
<h1>Assignment Name: <%=(ac == null)? "(None)": ac.getName() %> (<%=(ac == null)? "(None)": ac.getId() %>)</h1>
<table border="1px">
	<tr>
		<th>Student ID</th>
		<th>Name</th>
		<th>Group</th>
		<th>Submit Time</th>
		<th>File</th>
		<th>Status</th>
		<th>Mark</th>
	</tr>
<%
	if(!errMsg.isEmpty()) {
%>
	 <tr>
	 	<td colspan="7"><%=errMsg %></td>
	 </tr>
<%
	} else {
		try {
			UserControl uCon = new UserControl();
	 		Iterator<AssignmentResult> lrI = listResult.iterator();
	 		while(lrI.hasNext()) {
	 			AssignmentResult ar = lrI.next();
	 			Users aUser = uCon.getUser(ar.getSubmitBy());
%>
	<tr>
		<td><%=aUser.getId() %></td>
		<td><%=aUser.getName() %></td>
		<td><%=ar.getAgId() %></td>
		<td><%=(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(ar.getSubmitTime())) %></td>
		<td><%=ar.getFileName() %></td>
		<td><%=ar.getStatus().toString() %></td>
		<td><%=(((ar.getStatus() == SubmitStatus.marked) ? ar.getMark() : 0)+ " / "+ ac.getFullMark()) %></td>
	</tr>
<%
	 		}
	 		uCon.closeDBConnection();
		} catch (Exception e) {
			errMsg += e.toString() + "<br />\r\n";
		}
	}
	if(!errMsg.isEmpty()) {
%>
	<tr>
	 	<td colspan="7"><%=errMsg %></td>
	 </tr>
<% } %>
</table>
</body>
</html>